﻿using MediatR;
using T.Materials.Domain.Model;
using T.Materials.Read.API.ApplicationRead.Command.MaterialStoreCommand;
using T.Materials.Repository.MaterialsInterface;

namespace T.Materials.Read.API.ApplicationRead.CommandHandler.MaterialStoreCommandHandler
{
    /// <summary>
    /// 反填物资与入库命令处理器
    /// </summary>
    public class ReverseMaterialStoreCommandHandler : IRequestHandler<ReverseMaterialStoreCommand, MaterialStore>
    {
        /// <summary>
        /// 物资与入库仓储接口
        /// </summary>
        protected readonly IMaterialStoreRepository materialStoreRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="materialStoreRepository">物资与入库仓储接口</param>
        public ReverseMaterialStoreCommandHandler(IMaterialStoreRepository materialStoreRepository)
        {
            this.materialStoreRepository = materialStoreRepository;
        }

        /// <summary>
        /// 处理反填物资与入库命令
        /// </summary>
        /// <param name="request">反填物资与入库命令</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>反填后的物资与入库信息</returns>
        public async Task<MaterialStore> Handle(ReverseMaterialStoreCommand request, CancellationToken cancellationToken)
        {
            return await materialStoreRepository.GetModelAsync(request.MaterialStoreId);
        }
    }
}
